/**
 * 添加页面
 */
var DbExchangeInfoDlg = {
    data: {
        id: "",
        dbName: "",
        dbUrl: "",
        dbDescribe: "",
        state: "",
        // revision: "",
        // createdBy: "",
        // createdTime: "",
        // updatedBy: "",
        // updatedTime: ""
    }
};


layui.use(['table', 'admin', 'ax', 'func'], function () {
    var $ = layui.$;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;
    var layer = layui.layer;
    var form = layui.form;

    $("#returnForward").click(function () {
        history.go(-1)
    })

    /**
     * 为目标服务器下拉框赋值
     */
    $.ajax(Feng.ctxPath + '/databaseListKh/searchServer', {
        success: function (data) {
            $("#exchangeId").empty();
            $("#exchangeId").append("<option value=''>请选择服务器</option>");
            // console.log(data)
            for (let i = 0; i < data.length; i++) {
                $("#exchangeId").append(new Option(data[i].exchangeName, data[i].id))
            }
            //重新渲染
            form.render("select");
        }
    })

    /**
     * 选择值之后为
     */
    form.on('select(exchangeId)', function (data) {
        // console.log(data.value)
        if (data.value != null && data.value != "") {
            $.ajax(Feng.ctxPath + '/databaseListKh/searchServer', {
                data: {
                    id: data.value
                },
                success: function (data) {
                    // console.log(data)
                    if (data.length != 0) {
                        $("#exchangeUser").val(data[0].exchangeUser)
                        $("#exchangePassword").val(data[0].exchangePassword)
                    }
                }
            })
        } else {
            $("#exchangeUser").val("")
            $("#exchangePassword").val("")
        }

    })

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        // console.log(data.field)
        window.location.href = Feng.ctxPath + '/databaseListKh/add?exchangeDate=' + data.field.exchangeDate + '&exchangeId=' + data.field.exchangeId
        return false;
    });
});
